package com.example.databindingdemo;

import androidx.databinding.ObservableField;

import com.example.databindingdemo.model.LoginModel;

/**
 * @author: tuyrt7 on 2020/9/8.
 */
public class TwoWayBindingViewModel {

    private LoginModel mLoginModel;
    //使用ObservableField 包装 loginModel,进行双向绑定
    private ObservableField<LoginModel> mObservableField;

    public TwoWayBindingViewModel() {
        mLoginModel = new LoginModel();
        mLoginModel.userName = "tuyrt7";
        mObservableField = new ObservableField<>();
        mObservableField.set(mLoginModel);
    }

    public String getUserName() {
        return mObservableField.get().userName;
    }

    public void setUserName(String name) {
        mObservableField.get().userName = name;
    }
}
